<?
if(!defined('L_ADMOD')) {echo "<meta http-equiv='refresh' content='0; url=/?nma=error&act=403'>";exit;}
include("./inc/bloced.php");

if (($goto=='editfrm' && !isset($lid)) || ($goto=='editfrm' && $lid=='') || ($goto=='editfrm' && !is_numeric($lid)))
{
	print "<br><br><center><b>"._ERROR_.": "._NOITEMS_."</b></center>";
	echo "<meta http-equiv='refresh' content='2; url=/admin.php?op=".$op."'>";
}else
{
	include("admin/$op/menu.php");
	include("./php/wccatspaw2/spaw.inc.php");
	if ($goto=='editfrm')
	{
		$buttonTitle=_EDIT_;
		$formact_add="&taction=editlink&lid=".$lid."";
		$query_link=mysql_query("SELECT * FROM ${wcpref}".$op." WHERE mod_id='".$lid."'");
	}else
	{
		$buttonTitle=_ADD_;
		$formact_add="&taction=addlink";
	}
	
	if ($goto!='editfrm')
		$col_query_linlk1=1;
	else
		$col_query_linlk1=mysql_num_rows($query_link);
	if ($col_query_linlk1>1)	
	{
		print '<br><br><center><b><font color="#FF0000">'._ERROR_.'</font> '._ERROMANYENTRY_.'</b></center>';
		echo "<meta http-equiv='refresh' content='2; url=/admin.php?op=".$op."'>";
	}else
	{
		if ($goto=='editfrm')
			extract(mysql_fetch_array($query_link));
		else
		{
			$mod_wcps='';
			$mod_short='';
			$mod_full='';
			$mod_url='';
			$mod_reverse_url='';
			$mod_name='';
			$mod_cat_id=0;
		}
		if($mod_wcps==1)
		{
			print '<br><br><center><b><font color="#FF0000">'._ERROR_.'</font> '._ERROREDITWCPS_.'</b></center>';
			echo "<meta http-equiv='refresh' content='3; url=/admin.php?op=".$op."'>";
		}else
		{
			$cid=$mod_cat_id;
			$query_cat=mysql_query("SELECT * FROM ${wcpref}".$op."_category ORDER BY mod_category ASC");

			$quik_select='<select name="cid">';
			while($result_cat=mysql_fetch_array($query_cat))
			{
				extract($result_cat);
				if ($mod_id==$cid)
				{
					$mod_18_new=$mod_18;
					$select='selected';	
				}else
					$select='';
				if($wccat_allow18plus==0 && $mod_18==1)
				{
				}else
					$quik_select.='	<option value="'.$mod_id.'" '.$select.'>'.$mod_category;
				}
			$quik_select.='</select>';
			
			$spaw1 = new SpawEditor('new_short');	

			$spaw1->hideModeStrip();
			$spaw1->addToolbars("edit", "format", "my_insert", "table", "font", "style", "tools");
	
			$spaw1->addPage(new SpawEditorPage("new_short",(_TYPESHORT_."*"),$mod_short));
			$spaw1->addPage(new SpawEditorPage("new_full",_TYPEFULL_,$mod_full));
		
			print '<form name="form" method="post" action="'.$portal_subdir.'/admin.php?op='.$op.'&flag=doit&goto=linksfrm'.$formact_add.'">
				<table align="center" cellpadding="1" cellspacing="1" border="0" width="70%">
					<tr>
						<td colspan="2" align="center"><font color="#0000FF">'._STARMESSAGE_.'</font></td>
					</tr>
					<tr class="even">
						<td align="left" width="20%">'._SELECTCAT_.'*&nbsp;&nbsp;</td>
						<td align="left">'.$quik_select.'</td>
					</tr>
					<tr class="odd">
						<td align="left">'._TYPEURL_.'*&nbsp;&nbsp;</td>
						<td align="left"><input type="text" name="new_url" size="33" value="'.$mod_url.'">&nbsp;<font size="-3" color="#0000FF">('._WITHOUTHTTP_.')</font></td>
					</tr>
					<tr class="even">
						<td align="left">'._TYPERURL_.'&nbsp;&nbsp;</td>
						<td align="left"><input type="text" name="new_rurl" size="33" value="'.$mod_reverse_url.'">&nbsp;<font size="-3" color="#0000FF">('._WITHOUTHTTP_.')</font></td>
					</tr>
					<tr class="odd">
						<td align="left">'._TYPENAME_.'*&nbsp;&nbsp;</td>
						<td align="left">
							<input type="text" name="new_name" value="'.$mod_name.'" size="33" id="tname" onkeyup="Last50(this, 30, \'sname\', \'tname\');">&nbsp;<font size="-3" color="#0000FF">('._NAMETIPS_.')</font>
							<font color="#808080"><div id="sname">30</div></font>
						</td>
					</tr>
					<tr class="even">
						<td align="center" colspan="2">
							'._TYPEDESCRIPT_.'
						</td>
					</tr>
					<tr>
						<td align="center" colspan="2">';
							$spaw1->show();
						print'</td>
					</tr>
					<tr>
						<td align="center" colspan="2">
							<input type="submit" value="'.$buttonTitle.'">
						</td>
					</tr>
				</table>
			</form>';
		}
	}
}
?>

<script language="JavaScript">
	function Last50(m, limit, idsname, idtname)
	{
		var NameSize=m.value.length;
		var LastSize=limit-NameSize;
		var NameValue="";
		document.getElementById(idsname).innerHTML=LastSize;
					
		if (NameSize>limit)
		{
			document.getElementById(idtname).value=document.getElementById(idtname).value.substr(0,limit);
			document.getElementById(idsname).innerHTML="0";
			return;
		}
	}
	
</script>